package controllers;

import java.awt.event.ActionEvent;

import model.ButtonRequestModel;
import model.ComplaintReportModel;
import model.dateModel;
import model.packModel;
import view.ArchiveReportGUI;
import view.ComplaintReportGUI;
import view.PackageReportGUI;
import view.ProduceReportGUI;
import client.CliMessage;

/**
 * The Class ProduceReportController that AbstractController.
 * @author yudku
 */
public class ProduceReportController extends AbstractController
{	
	
	/** The Produce report view. */
	private ProduceReportGUI ProduceReportView;
	
	/** The Button request model. */
	private ButtonRequestModel ButtonRequestModel;
	
	/**
	 * This is produce report controller constructor.
	 *
	 * @param ProduceReportView is a produce report window GUI instance.
	 * @param ButtonRequestModel the button request model
	 */
	public ProduceReportController(ProduceReportGUI ProduceReportView, ButtonRequestModel ButtonRequestModel) 
	{
		super (ProduceReportView, ButtonRequestModel);
		this.ProduceReportView = ProduceReportView;
		this.ButtonRequestModel = ButtonRequestModel;

		this.ProduceReportView.addComplaintButtonListener(new ComplaintReportButtonListener(this));
		this.ProduceReportView.addArchiveButtonListener(new ArchiveReportButtonListener(this));
		this.ProduceReportView.addPackageButtonListener(new PackageReportButtonListener(this));
	
	}
	
	/**
	 * Inner class that handles when ComplaintReportButtonListener Button Pressed by request Id, implements Action listener.
	 *
	 * @author Tal & Yuda
	 */
	
	class ComplaintReportButtonListener extends AbstractListener
	{
		
		/** The previus observer. */
		private ProduceReportController previusObserver;
		
		/**
		 * Instantiates a new complaint report button listener.
		 *
		 * @param previusObserver the previus observer
		 */
		public ComplaintReportButtonListener (ProduceReportController previusObserver)
		{	
			this.previusObserver = previusObserver;
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) 
		{
			ComplaintReportGUI ComplaintReportView = new ComplaintReportGUI();
			ComplaintReportModel reqModel = new ComplaintReportModel();
			
			ComplaintReportController compController = new ComplaintReportController (ComplaintReportView, reqModel);
			
			setCurrentObserver(compController);	
			
			
			setBackListener(previusObserver, ComplaintReportView);
			
			String searchQuery = "search"	+ "SELECT * "
                                            + "FROM customer_complaints";
						                 
            sendToServer(searchQuery);				                       											
		}
	}
	
	
	/**
	 * The listener interface for receiving archiveReportButton events.
	 *
	 * @see ArchiveReportButtonEvent
	 */
	class ArchiveReportButtonListener extends AbstractListener
	{
		
		/** The previus observer. */
		private ProduceReportController previusObserver;
		
		/**
		 * Instantiates a new archive report button listener.
		 *
		 * @param previusObserver the previus observer
		 */
		public ArchiveReportButtonListener (ProduceReportController previusObserver )
		{
			this.previusObserver = previusObserver;
	
		}

		@Override
		public void actionPerformed(ActionEvent arg0) 
		{
			ArchiveReportGUI ArchiveReportView = new ArchiveReportGUI();
			ComplaintReportModel reqModel = new ComplaintReportModel();
			
			 ArchiveReportController compController = new ArchiveReportController (ArchiveReportView, reqModel);
			
			setCurrentObserver(compController);	
			
			
			setBackListener(previusObserver, ArchiveReportView);
			
			String searchQuery = "search"	+ "SELECT * "
                                            + "FROM daily_statistc";
						                 
            sendToServer(searchQuery);		                       											
		}
	}
	
	
	
	
	/**
	 * The listener interface for receiving packageReportButton events.
	 *
	 * @see PackageReportButtonEvent
	 */
	class PackageReportButtonListener extends AbstractListener
	{
	
		/** The previus observer. */
		private ProduceReportController previusObserver;
	
		
		/**
		 * Instantiates a new package report button listener.
		 *
		 * @param previusObserver the previus observer
		 */
		public PackageReportButtonListener (ProduceReportController previusObserver)
		{
			this.previusObserver = previusObserver;
	
		}
	
		@Override
		public void actionPerformed(ActionEvent arg0) 
		{
			
			PackageReportGUI PackageReportView = new PackageReportGUI();
			packModel reqModel = new packModel();
			
			PackageReportController compController = new PackageReportController (PackageReportView, reqModel);
			
			setCurrentObserver(compController);	
			
			
			setBackListener(previusObserver, PackageReportView);
			
			String searchQuery = "search"	+ "SELECT * "
                                            + "FROM customer_account";
						                 
            sendToServer(searchQuery);	
				                       											
		}
	}

	@Override
	public void handleDBRequestSuccess()
	{
	}
	
	@Override
	public void handleDBSearchResult(CliMessage dbResult) 
	{			
	}

	@Override
	public void handleNullSearchResult() 
	{
		//display main window
		
		ProduceReportView.setVisible(true);
		ProduceReportView.displayWrnMessage("NO DATA!");
	}
}
